<template>
    <!-- 添加或修改销售订单行项目信息对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="80%" append-to-body :close-on-click-modal="false" v-dialogDrag>
        <el-form ref="form" :model="form" :rules="rules" label-width="120px">
            <el-tabs v-model="activeName" class="detail-tab" type="card">
                <el-tab-pane label="基本信息" name="first">
                    <el-row :gutter="20">
                        <el-col :span="12">
                            <el-form-item label="采购方总部编码" prop="purchaserHqCode">
                                <el-input v-model="form.purchaserHqCode" placeholder="请输入采购方总部编码"/>
                            </el-form-item>
                        </el-col>
                        <el-col :span="12">
                            <el-form-item label="销售订单号" prop="soNo">
                                <el-input v-model="form.soNo" placeholder="请输入销售订单号"/>
                            </el-form-item>
                        </el-col>
                        <el-col :span="12">
                            <el-form-item label="品类编码" prop="categoryCode">
                                <el-input v-model="form.categoryCode" placeholder="请输入品类编码"/>
                            </el-form-item>
                        </el-col>
                        <el-col :span="12">
                            <el-form-item label="种类编码" prop="subclassCode">
                                <el-input v-model="form.subclassCode" placeholder="请输入种类编码"/>
                            </el-form-item>
                        </el-col>
                        <el-col :span="12">
                            <el-form-item label="销售订单行项目号" prop="soItemNo">
                                <el-input v-model="form.soItemNo" placeholder="请输入销售订单行项目号"/>
                            </el-form-item>
                        </el-col>
                        <el-col :span="12">
                            <el-form-item label="采购订单行项目ID" prop="poitemId">
                                <el-input v-model="form.poitemId" placeholder="请输入采购订单行项目ID"/>
                            </el-form-item>
                        </el-col>
                        <el-col :span="12">
                            <el-form-item label="物资编码" prop="productCode">
                                <el-input v-model="form.productCode" placeholder="请输入物资编码"/>
                            </el-form-item>
                        </el-col>
                        <el-col :span="12">
                            <el-form-item label="物资名称" prop="productName">
                                <el-input v-model="form.productName" placeholder="请输入物资名称"/>
                            </el-form-item>
                        </el-col>
                        <el-col :span="12">
                            <el-form-item label="物资单位" prop="productUnit">
                                <el-input v-model="form.productUnit" placeholder="请输入物资单位"/>
                            </el-form-item>
                        </el-col>
                        <el-col :span="12">
                            <el-form-item label="物资数量" prop="productAmount">
                                <el-input v-model="form.productAmount" placeholder="请输入物资数量"/>
                            </el-form-item>
                        </el-col>
                        <el-col :span="24">
                          <el-form-item label="备注" prop="remark">
                            <el-input v-model="form.remark" placeholder="请输入备注"/>
                          </el-form-item>
                        </el-col>
                        <!--<el-col :span="12">
                            <el-form-item label="数据拥有方" prop="ownerId">
                                <el-input v-model="form.ownerId" placeholder="请输入数据拥有方"/>
                            </el-form-item>
                        </el-col>
                        <el-col :span="12">
                            <el-form-item label="数据可见方" prop="openId">
                                <el-input v-model="form.openId" placeholder="请输入数据可见方"/>
                            </el-form-item>
                        </el-col>-->
                    </el-row>
                </el-tab-pane>
            </el-tabs>
        </el-form>
        <div slot="footer" class="dialog-footer">
            <el-button type="primary" @click="submitForm">确 定</el-button>
            <el-button @click="cancel">取 消</el-button>
        </div>
    </el-dialog>
</template>

<script>
    import { addAction, getById, updateAction } from '@/api/manage';
    import moment from 'moment';

    export default {
        name: "FactorySaleOrderColumnForm",
        data() {
            return {
                // 遮罩层
                loading: true,
                activeName: "first",
                // 弹出层标题
                title: "",
                // 是否显示弹出层
                open: false,
                // 表单参数
                form: {},
                // 表单校验
                rules: {
                },
                url: {
                    getById:'/factorySaleOrderColumn/factorySaleOrderColumn/',
                    add:'/factorySaleOrderColumn/factorySaleOrderColumn/add',
                    edit:'/factorySaleOrderColumn/factorySaleOrderColumn/edit',
                },
            };
        },
        created() {

        },
        methods: {
            // 取消按钮
            cancel() {
                this.open = false;
                this.reset();
            },
            // 表单重置
            reset() {
                this.form = {
            id: null,
        status: "0",
            remark: null,
            createBy: null,
            createTime: null,
            updateBy: null,
            updateTime: null,
            delFlag: null,
            purchaserHqCode: null,
            soNo: null,
            categoryCode: "60",
            subclassCode: "60004",
        soStatus: "0",
            soItemNo: null,
            poitemId: null,
            productCode: null,
            productName: null,
            productUnit: null,
            productAmount: null,
            ownerId: null,
            openId: null
                };
                this.resetForm("form");
            },
            /** 新增按钮操作 */
            handleAdd() {
                this.reset();
                this.open = true;
                this.title = "添加销售订单行项目信息";
            },
            /** 修改按钮操作 */
            handleUpdate(row) {
                this.reset();
                const id = row.id || this.ids;
                getById(this.url.getById, id).then(response => {
                    this.form = response.data;
                    this.open = true;
                    this.title = "修改销售订单行项目信息";
                });
            },
            /** 提交按钮 */
            submitForm() {
                this.$refs["form"].validate(valid => {
                    if (valid) {
                        if (this.form.id != null) {
                            updateAction(this.url.edit, this.form).then(response => {
                                this.$modal.msgSuccess("修改成功");
                                this.open = false;
                                this.$emit('ok');
                            });
                        } else {
                            addAction(this.url.add, this.form).then(response => {
                                this.$modal.msgSuccess("新增成功");
                                this.open = false;
                                this.$emit('ok');
                            });
                        }
                    }
                });
            },
        }
    };
</script>
